package cn.wd.page;

import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

@Getter
@Setter

public class PageResult<T> {

    private Integer currentPage;
    private Integer pageSize;

    private Long totalCount;
    private List<T> data;

    private Integer prevPage;
    private Integer nextPage;
    private Integer totalPage;

    public PageResult(Integer currentPage, Integer pageSize, Long totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;

        int intCount = totalCount.intValue();
        this.totalPage = intCount % pageSize == 0 ? intCount / pageSize : intCount / pageSize + 1;
        this.prevPage = Math.max(1, currentPage - 1);
        this.nextPage = Math.min(currentPage + 1, this.totalPage);
    }

    public static <T> PageResult<T> empty(Integer currentPage, Integer pageSize) {
        return new PageResult(currentPage, pageSize, 0L, Collections.emptyList());
    }
}